home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-09 | 22.8 KB | 888 lines | [TEXT/CWIE] |
- //
- // LTimeDateControl v1.0
- // A time and date picker for Power Plant.
- //
- // Copyright © 1995 by Michael F. Kamprath
- // mailto:kamprath@kagi.com
- // http://www.leonardo.net/kamprath/claireware.html
- //
- // Abstract
- // --------
- //
- // LTimeDateControl is a drop in module to give your Power Plant based application an
- // easy to use, graphical time and/or date picker. The user interface of LTimeDateControl
- // allows a user to click on a portion of a date and/or time string, and then change it's
- // value by clicking on an arrow or with the arrow keys.
- //
- // ConOps
- // ------
- //
- // To use, add a LControl pane to a view in your application and make it's class ID 'TmDt'.
- // Fill out it's values as you would a normal LControl with the following exceptions:
- //
- // 1. Min, Max, and Initial vlaue of the LControl is ignored. LTimeDateControl does
- // not use LControl's value tracking mechanism.
- //
- // 2. The user constant must be set to the variation of the LTimeDateControl you wish
- // to use. Variation IDs are:
- //
- // Type | ID
- // ===========================
- // Time only | 1
- // Long Date only | 2
- // Long Date & Time | 3
- // Short Date only | 4 (not supported yet in v1.0)
- // Short Date & Time | 5 (not supported yet in v1.0)
- //
- // 3. You may set a text traits ID for LTimeDateControl, but you must ensure the
- // frame you define for LTimeDateControl is at least the font's height plu 5 pixels
- // and an appropiate width to contain the date/time string plus 20 pixels in
- // width. Some expirementation will probably be needed to get the look you want.
- //
- // LTimeDateControl ignores LControl's value tracking mechanism in favor of it's
- // own. You may track a LTimeDateControl's value in either seconds (unsigned long)
- // or by a DateTimeRec. You may get the current value of LTimeDateControl with:
- //
- // Uint32 LTimeDateControl::GetDateTimeValue( void )
- // DateTimeRec LTimeDateControl::GetDateTimeRec( void )
- //
- // And set the current value with:
- //
- // void LTimeDateControl::SetDateTimeValue( const Uint32& inValue )
- // void LTimeDateControl::SetDateTimeValue( const DateTimeRec& inRec )
- //
- // When ever the user changes a LTimeDateControl value (note, not when it is
- // programatically changed), LTimeDateControl broadcasts a msg_TimeDateHasChanged
- // message (defined in LTimeDateControl.h) to any LListener's attached to the
- // LTimeDateControl. In the ioParameter of the message, the LTimeDateControl's pane
- // ID is passed.
- //
- // LTimeDateControl inherits off of LCommander (along with LControl) so that it will
- // de-hilite the currently selected date portion when it is no longer "in focus" and
- // to get keyDown messages.
- //
- // LTimeDateControl utilizes a StOffscreenGWorld so that a "smooth" redraw will be done.
- // Be sure to include the PowerPlant file "UGWorld.cp" in your project. LTimeDateControl
- // honors it's parent view's background color where appropiate (ensure that a call to
- // ApplyForeAndBackColors() will properly set it at the time of LTimeDateControl redraw).
- //
- // Be sure to also include the file LTimeDateControl.rsrc in your project. It contains
- // the control's arrow icons. Of course, you can change them to maintain your "look and feel"
- //
- // Legalisms
- // ---------
- //
- // You may freely use LTimeDateControl with the following exceptions:
- //
- // 1. If you use LTimeDateControl in your project, e-mail me so that I can keep you
- // posted when I release new versions.
- // 2. If you use LTimeDateControl in a project that you release to the public and
- // charge money for, I ask for a free & registered version of the product.
- // 3. No derivatives of LTimeDateControl may be publicly release with out my consent.
- //
-
- #include <TextUtils.h>
- #include <Icons.h>
- #include <string.h>
- #include <LString.h>
- #include <UGWorld.h>
- #include <UDrawingState.h>
- #include <UTextTraits.h>
- #include "LTimeDateControl.h"
-
- static void HiliteRect(Rect *theRect);
-
- const short kTimeStringPos = 5;
- const short kButtonIconHeight = 16;
- const short kButtonIconWidth = 16;
- const ResIDT kArrowButtonID = 15000;
-
- LTimeDateControl*
- LTimeDateControl::CreateTimeDateControlStream( LStream *inStream)
- {
- return (new LTimeDateControl(inStream));
- }
-
- LTimeDateControl::LTimeDateControl()
- : LControl(),
- mDateTimeValue(0)
- {
- this->InitDateTimeControl();
- }
- LTimeDateControl::LTimeDateControl( const LTimeDateControl &inOriginal)
- : LControl(inOriginal),
- mDateTimeValue(0)
- {
- this->InitDateTimeControl();
- }
- LTimeDateControl::LTimeDateControl( const SPaneInfo &inPaneInfo,
- MessageT inValueMessage,
- Uint32 inDateTimeValue,
- LTimeDateControl::ETimeDateControlType inVariation )
- : LControl(inPaneInfo,inValueMessage, 0, 0, 256),
- mVariation( inVariation ),
- mDateTimeValue(inDateTimeValue)
- {
- this->InitDateTimeControl();
- }
- LTimeDateControl::LTimeDateControl( LStream *inStream)
- : LControl(inStream),
- mDateTimeValue(0)
- {
- this->InitDateTimeControl();
- }
-
- LTimeDateControl::~LTimeDateControl()
- {
- if (this->mTimeFormatH)
- ::DisposeHandle( (Handle)this->mTimeFormatH );
- if (this->mDateFormatH)
- ::DisposeHandle( (Handle)this->mDateFormatH );
- }
-
- void
- LTimeDateControl::InitDateTimeControl( void )
- {
- this->mCntlTextTraitsID = this->GetMinValue();
-
- this->mVariation = (ETimeDateControlType)this->GetUserCon();
- this->mTimeFormatH = nil;
- this->mDateFormatH = nil;
- this->mCurrentHilite = 0;
-
- this->mTimeFormatH = (Intl0Hndl)::GetIntlResource( 0 );
- ::DetachResource( (Handle)this->mTimeFormatH );
- ::HNoPurge( (Handle)this->mTimeFormatH );
- (*this->mTimeFormatH)->timeFmt |= secLeadingZ | minLeadingZ | hrLeadingZ;
-
- this->mDateFormatH = (Intl1Hndl)::GetIntlResource( 1 );
- ::DetachResource( (Handle)this->mDateFormatH );
- ::HNoPurge( (Handle)this->mDateFormatH );
- (*this->mDateFormatH)->dayLeading0 = 255;
- this->InitDateStarts();
-
- }
-
- void
- LTimeDateControl::InitDateStarts( void )
- {
- short abbrLen, posNum, prevPosNum;
- short st0, st1, st2, st3;
-
- st0 = ::strlen( (*this->mDateFormatH)->st0 );
- st1 = ::strlen( (*this->mDateFormatH)->st1 );
- st2 = ::strlen( (*this->mDateFormatH)->st2 );
- st3 = ::strlen( (*this->mDateFormatH)->st3 );
-
- st0 = ( st0 < 4 ) ? st0 : 4;
- st1 = ( st1 < 4 ) ? st1 : 4;
- st2 = ( st2 < 4 ) ? st2 : 4;
- st3 = ( st3 < 4 ) ? st3 : 4;
-
- abbrLen = (*this->mDateFormatH)->abbrLen;
-
- if ( (*this->mDateFormatH)->lngDateFmt == 255 )
- {
- /* day name */
- this->mStartArray[ 1 ] = st0;
- if ( (*this->mDateFormatH)->suppressDay == 255 )
- this->mEndArray[ 1 ] = this->mStartArray[ 1 ];
- else
- this->mEndArray[ 1 ] = this->mStartArray[ 1 ] + abbrLen;
-
- /* month name */
- this->mStartArray[ 2 ] = this->mEndArray[ 1 ] + st1;
- this->mEndArray[ 2 ] = this->mStartArray[ 2 ] + abbrLen;
-
- /* date number */
- this->mStartArray[ 0 ] = this->mEndArray[ 2 ] + st2;
- this->mEndArray[ 0 ] = this->mStartArray[ 0 ] + 2;
-
- /* year */
- this->mStartArray[ 3 ] = this->mEndArray[ 0 ] + st3;
- this->mEndArray[ 3 ] = this->mStartArray[ 3 ] + 4;
-
- }
- else
- {
-
-
- /* first position */
- posNum = ( ((*this->mDateFormatH)->lngDateFmt)&3 );
- this->mStartArray[posNum] = st0 ;
- if (posNum == 0 ) /* date number */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 2;
- else if (posNum == 3 ) /* year item */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 4;
- else
- this->mEndArray[posNum] = this->mStartArray[posNum] + abbrLen;
-
- /* second position */
- prevPosNum = posNum;
- posNum = ( ((*this->mDateFormatH)->lngDateFmt)&12 )/4;
- this->mStartArray[posNum] = this->mEndArray[prevPosNum] + st1 ;
- if (posNum == 0 ) /* date number */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 2;
- else if (posNum == 3 ) /* year item */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 4;
- else
- this->mEndArray[posNum] = this->mStartArray[posNum] + abbrLen;
-
- /* third position */
- prevPosNum = posNum;
- posNum = ( ((*this->mDateFormatH)->lngDateFmt)&48 )/16;
- this->mStartArray[posNum] = this->mEndArray[prevPosNum] + st2 ;
- if (posNum == 0 ) /* date number */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 2;
- else if (posNum == 3 ) /* year item */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 4;
- else
- this->mEndArray[posNum] = this->mStartArray[posNum] + abbrLen;
-
- /* fourth position */
- prevPosNum = posNum;
- posNum = ( ((*this->mDateFormatH)->lngDateFmt)&192 )/64;
-
- this->mStartArray[posNum] = this->mEndArray[prevPosNum] + st3 ;
- if (posNum == 0 ) /* date number */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 2;
- else if (posNum == 3 ) /* year item */
- this->mEndArray[posNum] = this->mStartArray[posNum] + 4;
- else
- this->mEndArray[posNum] = this->mStartArray[posNum] + abbrLen;
-
-
- }
-
- }
-
- void
- LTimeDateControl::ClickSelf(const SMouseDownEvent &inMouseDown)
- {
- if (!this->IsTarget())
- this->SwitchTarget(this);
-
- this->LControl::ClickSelf(inMouseDown);
- }
- void
- LTimeDateControl::BeTarget()
- {
- }
-
- void
- LTimeDateControl::DontBeTarget()
- {
- this->mCurrentHilite = 0;
- this->FocusDraw();
- this->DrawDateTimeControl();
- }
- void
- LTimeDateControl::ActivateSelf()
- {
- this->FocusDraw();
- this->DrawDateTimeControl();
- }
- void
- LTimeDateControl::DeactivateSelf()
- {
- this->FocusDraw();
- this->DrawDateTimeControl();
- }
-
- Boolean
- LTimeDateControl::HandleKeyPress( const EventRecord &inKeyEvent)
- {
- Boolean returnVal = false;
- Char16 theKey = inKeyEvent.message;
- Uint16 theHotSpot;
-
- switch (theKey & charCodeMask)
- {
-
- case char_UpArrow:
- theHotSpot = kInUpArrow;
- this->ArrowAction( theHotSpot, true );
- this->HotSpotResult( theHotSpot );
- returnVal = true;
- break;
- case char_DownArrow:
- theHotSpot = kInDownArrow;
- this->ArrowAction( theHotSpot, true );
- this->HotSpotResult( theHotSpot );
- returnVal = true;
- break;
- case char_LeftArrow:
- case char_RightArrow:
- default:
- returnVal = this->LCommander::HandleKeyPress(inKeyEvent);
- break;
- }
-
- return returnVal;
- }
- Boolean
- LTimeDateControl::FocusDraw()
- {
- Boolean focused = LControl::FocusDraw();
-
- UTextTraits::SetPortTextTraits( this->mCntlTextTraitsID );
-
- return focused;
- }
- void
- LTimeDateControl::DrawSelf( )
- {
- this->DrawDateTimeControl( );
- }
-
- void
- LTimeDateControl::DrawDateTimeControl( const Uint16& theHotSpot )
- {
- Rect contrlRect, strRect, workRect;
- RGBColor whiteColor = {0xFFFF,0xFFFF,0xFFFF};
- RGBColor foreColor, backColor;
- Point thePt;
- short iconID;
-
- ::GetForeColor(&foreColor);
- ::GetBackColor(&backColor);
-
- this->CalcLocalFrameRect( contrlRect );
-
- StOffscreenGWorld offWorld(contrlRect);
-
- this->ApplyForeAndBackColors();
-
- strRect = contrlRect;
- strRect.right = contrlRect.right - kTimeStringPos - kButtonIconWidth;
-
- if (this->IsActive())
- {
- ::EraseRect(&contrlRect);
- ::RGBBackColor(&whiteColor);
- ::EraseRect(&strRect);
- ::FrameRect(&strRect);
-
- UTextTraits::SetPortTextTraits( this->mCntlTextTraitsID );
-
- thePt.h = strRect.left + kTimeStringPos;
- thePt.v = strRect.bottom - 5;
-
- switch (this->mVariation)
- {
- case kTimeVariation:
- this->DrawTimeString( thePt, strRect, this->mCurrentHilite );
- break;
- case kLongDateVariation:
- this->DrawLongDateString( thePt, strRect, this->mCurrentHilite );
- break;
- case kLongDateAndTimeVariation:
- thePt.h += this->DrawLongDateString( thePt, strRect, this->mCurrentHilite ) + kTimeStringPos;
- this->DrawTimeString( thePt, strRect, this->mCurrentHilite );
- break;
-
- }
-
- if (this->mCurrentHilite)
- {
- if (theHotSpot&kInUpArrow)
- iconID = kArrowButtonID + 1;
- else if (theHotSpot&kInDownArrow)
- iconID = kArrowButtonID + 2;
- else
- iconID = kArrowButtonID;
-
- SetRect(&workRect, strRect.right + kTimeStringPos,
- strRect.top + (strRect.bottom - strRect.top)/2 - kButtonIconHeight/2,
- strRect.right + kTimeStringPos + kButtonIconWidth,
- strRect.top + (strRect.bottom - strRect.top)/2 + kButtonIconHeight/2);
- PlotIconID(&workRect, atVerticalCenter, ttNone, iconID);
- }
- }
- else
- {
- RGBColor foreColor, oldForColor, backColor;
- GDHandle devH;
-
- ::EraseRect(&contrlRect);
- ::RGBBackColor(&whiteColor);
- ::EraseRect(&strRect);
- ::FrameRect(&strRect);
-
- UTextTraits::SetPortTextTraits( this->mCntlTextTraitsID );
- thePt.h = strRect.left + kTimeStringPos;
- thePt.v = strRect.bottom - 5;
-
- devH = ::GetGDevice( );
- ::GetForeColor( &foreColor );
- oldForColor = foreColor;
- ::GetBackColor( &backColor );
- ::GetGray( devH, &backColor, &foreColor );
- ::RGBForeColor( &foreColor );
-
-
- switch (this->mVariation)
- {
- case kTimeVariation:
- this->DrawTimeString( thePt, strRect, 0 );
- break;
- case kLongDateVariation:
- this->DrawLongDateString( thePt, strRect, 0 );
- break;
- case kLongDateAndTimeVariation:
- thePt.h += this->DrawLongDateString( thePt, strRect, 0 ) + kTimeStringPos;
- this->DrawTimeString( thePt, strRect, 0 );
- break;
- }
-
- ::RGBForeColor(&oldForColor);
- }
-
-
- this->SetForeAndBackColors( &foreColor, &backColor );
- }
-
- Int16
- LTimeDateControl::DrawTimeString( const Point& startPos,
- const Rect& strRect,
- const Uint16& hilite )
- {
- Str255 timeStr, tempStr;
- short startH, endH;
- Rect workRect;
-
- ::TimeString(this->mDateTimeValue, false, timeStr, (Handle)this->mTimeFormatH );
-
- ::MoveTo(startPos.h, startPos.v);
- ::DrawString( timeStr );
-
- if (hilite&kTimeHiliteMask)
- {
- LString::CopyPStr( timeStr, tempStr);
- if (hilite == kHourItem)
- {
- startH = 0;
- tempStr[0] = 2;
- endH = ::StringWidth(tempStr);
- }
- else if ( hilite == kMinuteItem )
- {
- if ((*mTimeFormatH)->timeSep)
- {
- tempStr[0] = 3;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 5;
- endH = ::StringWidth(tempStr);
- }
- else
- {
- tempStr[0] = 2;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 4;
- endH = ::StringWidth(tempStr);
- }
- }
- else if ( hilite == kSecondItem )
- {
- }
- else if ( hilite == kAMPMItem )
- {
- if ((*mTimeFormatH)->timeSep)
- {
- tempStr[0] = 6;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 8;
- endH = ::StringWidth(tempStr);
- }
- else
- {
- tempStr[0] = 5;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 7;
- endH = ::StringWidth(tempStr);
- }
- }
- ::SetRect(&workRect, startH + startPos.h, strRect.top + 3,
- endH + startPos.h, strRect.bottom - 2);
- ::HiliteRect( &workRect );
-
- }
-
- return ::StringWidth( timeStr );
- }
- Int16
- LTimeDateControl::DrawLongDateString( const Point& startPos,
- const Rect& strRect,
- const Uint16& hilite )
- {
- Str255 dateStr, tempStr;
- short startH, endH;
- Rect workRect;
-
-
- ::DateString( this->mDateTimeValue, abbrevDate, dateStr, (Handle)this->mDateFormatH);
-
- ::MoveTo(startPos.h, startPos.v);
- ::DrawString( dateStr );
-
-
- if (hilite&kDateHiliteMask)
- {
- LString::CopyPStr( dateStr, tempStr);
-
- if (hilite == kDayOfWeekItem)
- {
- tempStr[0] = this->mStartArray[1];
- startH = ::StringWidth(tempStr) + startPos.h;
-
- tempStr[0] = this->mEndArray[1];
- endH = ::StringWidth(tempStr) + startPos.h;
- }
- else if (hilite == kMonthItem)
- {
- tempStr[0] = this->mStartArray[2];
- startH = ::StringWidth(tempStr) + startPos.h;
-
- tempStr[0] = this->mEndArray[2];
- endH = ::StringWidth(tempStr) + startPos.h;
- }
- else if (hilite == kDateItem)
- {
- tempStr[0] = this->mStartArray[0];
- startH = ::StringWidth(tempStr) + startPos.h;
-
- tempStr[0] = this->mEndArray[0];
- endH = ::StringWidth(tempStr) + startPos.h;
- }
- else if (hilite == kYearItem)
- {
- tempStr[0] = this->mStartArray[3];
- startH = ::StringWidth(tempStr) + startPos.h;
-
- tempStr[0] = this->mEndArray[3];
- endH = ::StringWidth(tempStr) + startPos.h;
- }
- ::SetRect(&workRect, startH, strRect.top + 3,
- endH, strRect.bottom - 2);
- ::HiliteRect( &workRect );
- }
-
- return ::StringWidth( dateStr );
- }
- Int16
- LTimeDateControl::FindHotSpot(Point inPoint)
- {
- Rect contrlRect, testRect;
- Int16 width;
- Uint16 theHotSpot = kNoPart;
-
- this->CalcLocalFrameRect( contrlRect );
-
- // first, test up & down arrows
- SetRect(&testRect, contrlRect.right - kButtonIconWidth,
- contrlRect.top + (contrlRect.bottom - contrlRect.top)/2 - kButtonIconHeight/2,
- contrlRect.right,
- contrlRect.top + (contrlRect.bottom - contrlRect.top)/2 + kButtonIconHeight/2);
- if (::PtInRect( inPoint, &testRect))
- {
- if ( inPoint.v < (testRect.bottom + testRect.top)/2 )
- return kInUpArrow;
- else
- return kInDownArrow;
- }
-
- // not in arrows so in text?
-
- switch (this->mVariation)
- {
- case kTimeVariation:
- testRect = contrlRect;
- testRect.left += kTimeStringPos;
- testRect.right = contrlRect.right - kTimeStringPos - kButtonIconWidth;
- theHotSpot = this->TestTimeString( testRect, inPoint, width );
- break;
- case kLongDateVariation:
- testRect = contrlRect;
- testRect.left += kTimeStringPos;
- testRect.right = contrlRect.right - kTimeStringPos - kButtonIconWidth;
- theHotSpot = this->TestLongDateString( testRect, inPoint, width );
- break;
- case kLongDateAndTimeVariation:
- testRect = contrlRect;
- testRect.left += kTimeStringPos;
- testRect.right = contrlRect.right - kTimeStringPos - kButtonIconWidth;
- theHotSpot = this->TestLongDateString( testRect, inPoint, width );
- if (!theHotSpot)
- {
- testRect.left += kTimeStringPos + width;
- theHotSpot = this->TestTimeString( testRect, inPoint, width );
- }
- break;
- }
-
- if (!theHotSpot)
- this->DontBeTarget();
-
- return theHotSpot;
- }
-
- void
- LTimeDateControl::HotSpotAction( Int16 inHotSpot,
- Boolean inCurrInside,
- Boolean inPrevInside)
- {
-
- if (inCurrInside)
- {
- if ( inHotSpot&kArrowPartMask )
- this->ArrowAction( inHotSpot, (inCurrInside == inPrevInside) );
- }
- else
- {
- this->FocusDraw();
- this->DrawDateTimeControl();
- }
-
- }
-
- void
- LTimeDateControl::ArrowAction( Uint16 inHotSpot, Boolean holdClick )
- {
- Uint32 deltaVal;
- DateTimeRec theDate;
-
- if (this->mCurrentHilite&kDateHiliteMask)
- ::SecondsToDate(this->mDateTimeValue, &theDate);
- switch (inHotSpot&kArrowPartMask)
- {
- case kInUpArrow:
- deltaVal = 1;
- break;
- case kInDownArrow:
- deltaVal = -1;
- break;
- default:
- deltaVal = 0;
- break;
- }
- if ( (!holdClick)||( holdClick&&( ::TickCount() > this->mLastClickTickCount + 10 )) )
- {
- this->mLastClickTickCount = ::TickCount();
- switch (this->mCurrentHilite)
- {
- case kMonthItem:
- theDate.month += deltaVal;
- break;
- case kDateItem:
- case kDayOfWeekItem:
- theDate.day += deltaVal;
- break;
- case kYearItem:
- theDate.year += deltaVal;
- break;
- case kHourItem:
- this->mDateTimeValue += deltaVal*3600;
- break;
- case kMinuteItem:
- this->mDateTimeValue += deltaVal*60;
- break;
- case kSecondItem:
- this->mDateTimeValue += deltaVal;
- break;
- case kAMPMItem:
- this->mDateTimeValue += deltaVal*12*3600;
- break;
-
- }
- }
- if (this->mCurrentHilite&kDateHiliteMask)
- ::DateToSeconds( &theDate, &this->mDateTimeValue);
-
- this->FocusDraw();
- this->DrawDateTimeControl( inHotSpot );
- }
-
- void
- LTimeDateControl::HotSpotResult( short inHotSpot)
- {
-
- if ( inHotSpot&kTextComponentMask )
- this->mCurrentHilite = inHotSpot&kTextComponentMask;
-
- this->HotSpotAction(inHotSpot, false, true); // Undo hilighting
-
- if (inHotSpot&kArrowPartMask)
- this->BroadcastMessage( msg_TimeDateHasChanged, (void *)this->GetPaneID() ); // send message to inform Listeners
- }
-
- Uint16
- LTimeDateControl::TestTimeString( const Rect& strRect, const Point& hitPt, Int16& width )
- {
- Rect partRect;
- Str255 timeStr, tempStr;
- short startH, endH;
-
- this->FocusDraw();
- ::TimeString(this->mDateTimeValue, false, timeStr, (Handle)this->mTimeFormatH );
- width = ::StringWidth(timeStr);
-
- if(::PtInRect(hitPt, &strRect))
- {
- LString::CopyPStr(timeStr, tempStr);
-
- // Hour Item
- startH = 0;
- tempStr[0] = 2;
- endH = ::StringWidth(tempStr);
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kHourItem;
-
- // minute item
- if ((*mTimeFormatH)->timeSep)
- {
- tempStr[0] = 3;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 5;
- endH = ::StringWidth(tempStr);
- }
- else
- {
- tempStr[0] = 2;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 4;
- endH = ::StringWidth(tempStr);
- }
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kMinuteItem;
-
- // AM PM item
- if ((*mTimeFormatH)->timeSep)
- {
- tempStr[0] = 6;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 8;
- endH = ::StringWidth(tempStr);
- }
- else
- {
- tempStr[0] = 5;
- startH = ::StringWidth(tempStr);
- tempStr[0] = 7;
- endH = ::StringWidth(tempStr);
- }
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kAMPMItem;
-
- }
- return kNoPart;
- }
-
- Uint16
- LTimeDateControl::TestLongDateString( const Rect& strRect, const Point& hitPt, Int16& width )
- {
- Rect partRect;
- Str255 dateStr, tempStr;
- short startH, endH;
-
- this->FocusDraw();
- ::DateString( this->mDateTimeValue, abbrevDate, dateStr, (Handle)this->mDateFormatH);
- width = ::StringWidth(dateStr);
-
- if(::PtInRect(hitPt, &strRect))
- {
- LString::CopyPStr(dateStr, tempStr);
-
- /* Day Name item */
- tempStr[0] = this->mStartArray[1];
- startH = ::StringWidth(tempStr);
-
- tempStr[0] = this->mEndArray[1];
- endH = ::StringWidth(tempStr);
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kDayOfWeekItem;
-
- /* Month Item */
- tempStr[0] = this->mStartArray[2];
- startH = ::StringWidth(tempStr);
-
- tempStr[0] = this->mEndArray[2];
- endH = ::StringWidth(tempStr);
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kMonthItem;
-
- /* date num item */
- tempStr[0] = this->mStartArray[0];
- startH = ::StringWidth(tempStr);
-
- tempStr[0] = this->mEndArray[0];
- endH = ::StringWidth(tempStr);
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kDateItem;
-
- /* year item */
- tempStr[0] = this->mStartArray[3];
- startH = ::StringWidth(tempStr);
-
- tempStr[0] = this->mEndArray[3];
- endH = ::StringWidth(tempStr);
- ::SetRect(&partRect, strRect.left + startH, strRect.top,
- strRect.left + endH, strRect.bottom);
- if (::PtInRect(hitPt, &partRect))
- return kYearItem;
-
- }
-
- return kNoPart;
- }
- DateTimeRec
- LTimeDateControl::GetDateTimeRec( void ) const
- {
- DateTimeRec outRec;
-
- ::SecondsToDate( this->mDateTimeValue, &outRec );
-
- return outRec;
- }
- void
- LTimeDateControl::SetDateTimeValue( const DateTimeRec& inRec )
- {
- DateToSeconds( &inRec, &this->mDateTimeValue );
- this->Refresh();
- }
- Uint32
- LTimeDateControl::GetDateTimeValue( void ) const
- {
- return this->mDateTimeValue;
- }
- void
- LTimeDateControl::SetDateTimeValue( const Uint32& inValue )
- {
- this->mDateTimeValue = inValue;
- this->Refresh();
- }
-
-
-
- static void HiliteRect(Rect *theRect)
- {
- unsigned char oldMode;
-
- oldMode = LMGetHiliteMode();
- LMSetHiliteMode( 1 );
- InvertRect(theRect);
- LMSetHiliteMode( oldMode );
- }
-
-